<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="icon" href="images/icon.jpg">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/common.css">
    <script src="js/jquery-2.1.4.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <style>
        .title-line{
            border-bottom: 1px solid #dddddd;
            margin-bottom: 28px;
            text-align: center;
            height: 28px;
        }
        .title-line .tit{
            font-size: 38px;
            line-height: 56px;
            height: 56px;
            padding:0 20px;
            text-align: center;
        }
        form button[type="submit"]:hover{
            background-color: #eeeeee;
            color: white;
        }
    </style>

</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="/index.html" class="navbar-brand logo">
                <img src="/images/icon.jpg" width="50px" alt="">
            </a>
            <a class="navbar-brand" href="/index.html">
                <span>义启行</span>
            </a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="active"><a href="/index.html">首页<span class="sr-only">(current)</span></a></li>
                <li><a href="#">Link</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#">Separated link</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#">One more separated link</a></li>
                    </ul>
                </li>
            </ul>
            <form class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Search">
                </div>
                <button type="submit" class="btn btn-default">Submit</button>
            </form>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/discussion.html">讨论</a></li>
                <li class="publish"><a href="/publish.html">分享</a></li>
                <li><a href="/recruit.html" class="recruitTab" style="display: none;">发布招募</a></li>
                <li class="authTab"><a href="/login.html">登录</a></li>
                <li class="authTab"><a href="/register.html">注册</a></li>
                <li class="dropdown user" style="display: none">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">
                        <span>
                            <span>
                                <img class="avatarUrl img-circle" src="/images/adorable.jpg" alt="">
                            </span>
                            <span class="nickname"></span>
                        </span>
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <input type="hidden" value="-1" class="role">
                        <li><a href="/personal.html">个人信息</a></li>
                        <li><a href="/replies.html">回复我的</a></li>
                        <li><a href="/signupInfo.html">报名信息</a></li>
                        <li><a href="/logout">退出登录</a></li>
                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">

        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="title-line">
                <span class="tit">注册</span>
            </div>
        </div>
    </div>
    <div class="row">
        <div class=" col-md-offset-3 col-md-6  col-lg-offset-3 col-lg-6  col-sm-10 col-sm-offset-1 col-xs-10 col-xs-offset-1 ">
            <div class=" clearfix">
                <form class="register" action="/register" method="post" onsubmit="return check()">
                    <div class="form-group">
                        <!--                            <label for="username">Email address</label>-->
                        <input type="text" class="form-control" id="nickname" placeholder="用户名" name="nickname">
                    </div>
                    <div class="form-group">
                        <!--                            <label for="password">Password</label>-->
                        <input type="password" class="form-control" id="password" placeholder="密码" name="password" autocomplete="">
                    </div>
                    <div class="form-group">
                        <input type="email" class="form-control" id="email" name="account" placeholder="填写常用邮箱">
                    </div>
                    <div class="form-group">
                        <input type="text" class="form-control" id="VRCode" placeholder="请输入邮箱验证码" name="VRCode">
                        <div class="form-control clickToGet">点击获取</div>
                    </div>
                    <div class="form-group">
                        <select name="role" id="role" class="form-control">
                            <option value="" disabled selected hidden>请选择身份--</option>
                            <option value="1">换宿义工</option>
                            <option value="2">民宿店家</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <div class="tick">
                            <label>
                                <input type="checkbox">我已同意
                                <a href="">《XXX协议》</a>和
                                <a href="">《XXX政策》</a>
                            </label>
                        </div>
                        <button type="submit" class="form-control" disabled="disabled">注册</button>
                        <a href="/login" class="pull-right">已有帐号，直接登录></a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


</body>
<script>
    $(".tick label").click(function () {
        var status=$(".form-group .tick input").prop("checked");
        var selector = "button[type='submit']";
        if(status===true){
            $(selector).prop("disabled",false);
            $(selector).addClass("hover");
        }else if(status===false){
            $(selector).prop("disabled",true);
            $(selector).removeClass("hover");
        }
    });
    function check(){
        let nickname  = $("#nickname").val();
        let password = $("#password").val();
        let role = $("#role").val();
        if(nickname==null||nickname.trim()===""){
            alert("用户名不能为空！！！");
            return false;
        }
        if(password==null||password.trim()===""){
            alert("密码不能为空！！！");
            return false;
        }
        if(role==null||role.trim()===""){
            alert("请选择身份！！！");
            return false;
        }
        return true;
    }
    $(".clickToGet").click(function () {
        var regExp = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
        let email = $("#email").val().trim();
        if(email==null||email===""){
            return false;
        }
        if(!regExp.test(email)){
            alert("邮箱非法！！！")
            return false;
        }
        alert("已发送验证码至邮箱："+email);
        $.ajax({
            url:"/retrieveVRCode",
            type:"POST",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            data:JSON.stringify({
                "email":email
            }),
            success:function (response) {
                if(response.code!==200){
                    alert("该邮箱已经注册过了！！")
                }
                console.log(response);
            },
            error:function (error) {
                console.log(error);
            }
        });
    });

</script>
<script src="/js/common.js"></script>
<script>authenticate()</script>

</html>